package com.tougutips.cookbook.controller.es;

import com.ruoyi.common.core.domain.R;
import com.tougutips.cookbook.entity.Cookbook;
import com.tougutips.cookbook.service.es.CookbookServiceES;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author YSY
 * @Description
 * @DateTime 2022/7/21 20:10
 * @Email 296242766@qq.com
 */
@RestController
@RequestMapping("/content/cookbook/es")
public class CookbookControllerES {
    private final CookbookServiceES cookbookServiceES;
    @Autowired
    public CookbookControllerES(CookbookServiceES cookbookServiceES) {
        this.cookbookServiceES = cookbookServiceES;
    }

    @GetMapping("/search")
    public R<List<Cookbook>> findName(String keyword){
        List<Cookbook> cookbooks = cookbookServiceES.findName(keyword);
        return R.ok(cookbooks);
    }

    @RequestMapping("/all")
    public R<List<Cookbook>> findAll(){
        return R.ok(cookbookServiceES.findAll());
    }

    @GetMapping("/{id}")
    public R<Cookbook> findById(@PathVariable Long id){
        Cookbook cookbook = cookbookServiceES.findById(id);
        return R.ok(cookbook);
    }
    @PutMapping("/save")
    public R<Cookbook> save(@RequestBody Cookbook cookbook){
        Cookbook one = cookbookServiceES.addOne(cookbook);
        return R.ok(one);
    }
}
